package com.sanley.piss.web.controller;

import com.sanley.piss.model.exceptionUtil.json.JsonResult;
import com.sanley.piss.model.po.DictionaryType;
import com.sanley.piss.web.service.mapper.IDictionaryTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * Create By  on 2021/3/22.
 */
@Api(value = "数据字典类型controller",tags = "数据字典类型操作接口")
@RestController
@RequestMapping("/dictype")
public class DictionaryTypeController {

    @Autowired
    private IDictionaryTypeService service;

    @ApiOperation(value = "增加一条记录")
    @RequestMapping(value = "/insert",method = RequestMethod.PUT)
    public JsonResult<Object> insert(@Valid DictionaryType type){
        service.insert(type);
        return JsonResult.success();
    }

    @ApiOperation(value = "根据ID删除多条记录")
    @RequestMapping(value = "/delete/{ids}",method = RequestMethod.DELETE)
    public JsonResult<Object> delete(@PathVariable("ids") Integer[] ids){
            service.removeByIds(ids);
        return JsonResult.success();
    }

    @ApiOperation(value = "修改一条记录")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public JsonResult<Object> update(@Valid DictionaryType type){
       service.updateById(type);
        return JsonResult.success();
    }

    @ApiOperation(value = "根据ID查询一条记录")
    @RequestMapping(value = "/selectById",method = RequestMethod.GET)
    public JsonResult<DictionaryType> selectById(Integer id){
        return JsonResult.success(service.selectById(id));
    }

    @ApiOperation(value = "查询所有记录")
    @RequestMapping(value = "/selectAll",method = RequestMethod.GET)
    public JsonResult<List<DictionaryType>> selectAll(){
        return JsonResult.success(service.selectAll());
    }
}
